install_and_load <- function(pkg){
  if (!require(pkg, character.only = TRUE)) {
    install.packages(pkg, dependencies = TRUE)
    library(pkg, character.only = TRUE)
  }
}

packages <- c("tidyverse", "texreg", "foreign", "rdd", "rdrobust", "rdlocrand",
              "rddtools", "stargazer", "rdpower", "broom", "srvyr", "hIRT",
              "lme4", "labelled", "showtext", "interflex", "sandwich", 
              "ggExtra")

invisible(lapply(packages, install_and_load))

sessionInfo()
